//
//  CardView.m
//  SinaWebo
//
//  Created by wwj on 16/7/6.
//  Copyright © 2016年 亦心. All rights reserved.
//

#import "CardView.h"
#import "PageInfo.h"
#import "CVideoView.h"
#import "CNewsView.h"
#import "CAtrView.h"

@interface CardView ()
@property (weak, nonatomic) CVideoView *videoView;
@property (weak, nonatomic) CNewsView *newsView;
@property (weak, nonatomic) CAtrView *atrView;
@end

@implementation CardView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
    }
    return self;
}

- (void)initView{
    self.backgroundColor = [UIColor whiteColor];
    
    CVideoView *videoView = [CVideoView videoView];
    videoView.frame = self.bounds;
    videoView.hidden = YES;
    [self addSubview:videoView];
    self.videoView = videoView;
    
    CNewsView *newsView = [CNewsView newsView];
    newsView.hidden = YES;
    newsView.frame = self.bounds;
    [self addSubview:newsView];
    self.newsView = newsView;
    
    CAtrView *atrView = [CAtrView atrView];
    atrView.frame = self.bounds;
    atrView.hidden = YES;
    [self addSubview:atrView];
    self.atrView = atrView;
}

- (void)layoutSubviews{
    [super layoutSubviews];
}


- (void)setPageInfo:(PageInfo *)pageInfo{
    _pageInfo = pageInfo;
    if (pageInfo.type == PageInfoTypeVideo) {
        _videoView.hidden = NO;
        _videoView.frame = self.bounds;
        _newsView.hidden = YES;
        _atrView.hidden = YES;
        _videoView.pageInfo = _pageInfo;
       
    }else if (pageInfo.type == PageInfoTypeNews){
        _videoView.hidden = YES;
        _newsView.hidden = NO;
        _newsView.frame = self.bounds;
        _atrView.hidden = YES;
        _newsView.pageInfo = _pageInfo;
        
    }else if (pageInfo.type == PageInfoTypeAtric){
        _videoView.hidden = YES;
        _newsView.hidden = YES;
        _atrView.hidden = NO;
        _atrView.frame = self.bounds;
        _atrView.pageInfo = _pageInfo;
    }else{
        MyLog(@"");
    }
}

- (void)stopVideo{
    [_videoView stopVideo];
}

- (void)playVideo{
    [_videoView playVideo];
}

@end
